// 定义监测数据变化函数

import observe from './observe.js'

export default function defineReactive(data, key, val) {
  if (arguments.length === 2) {
    val = data[key]
  }
  observe(val)
  Object.defineProperty(data, key, {
    enumerable: true,
    configurable: true,
    get () {
      console.log(data)
      console.log('读取数据' + key)
      return val
    },
    set (newValue) {
      console.log(data)
      console.log('设置数据' + key)
      if (val === newValue) {
        return
      }
      observe(newValue)
      val = newValue
    }
  })
}